<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class ManagerroleController extends BaseController {
    public function index(){
    	//管理员详情展示信息（显示5条）
    	$M = M("admin_role");
    	$role_info=$M->select();
    	$this->assign("role_info",$role_info);
        $this->display(index);
    }
    public function add_role(){
    	//添加角色方法
    	$data=I("post.");
    	$M = M("admin_role");
    	$data = $M->create();
        $data["admin_role"]=trim($data["admin_role"]);
        $data["admin_desc"]=trim($data["admin_desc"]);
        $M->add($data);
        redirect(U("Managerrole/index"),0,"页面跳转中···");
    }
    public function del_role(){
    	//删除角色方法
    	$data=I("get.");
    	$id=$data["id"];
    	$M = M("admin_role");
        $M->startTrans();
    	$res1=$M->where("id='$id'")->delete();
        $M->table("__ADMIN_ACCESS__");
        $res2=$M->where("role_id='$id'")->delete();
        if($res1&&$res2){
            $M->commit();
        }else{
            $M->rollback();
        }
    	redirect(U("Managerrole/index"),0,"页面跳转中···");
    }
    public function edit_role(){
    	//编辑角色方法
    	$data=I("get.");
    	$id=$data["id"];
    	$M = M("admin_role");
    	$role_info=$M->where("id='$id'")->find();
    	$this->assign("role_info",$role_info);
    	$this->display();
    }
    public function edit_role_do(){
    	//编辑角色处理方法
    	$data=I("post.");
    	$id=$data["id"];
    	$M = M("admin_role");
        $data= $M->create();
        $M->where("id=$id")->save($data);
        redirect(U("Managerrole/index"),0,"页面跳转中···");
    }
}